
import React from "react";
import { hashHistory } from 'react-router';
import Util from "../../util/Util";

/*导出组件*/
export default class Manager_item extends React.Component {
    constructor(props) {
        super(props)
        this.state={
            context:[]
        };
        this.name=[];
        this.context = [];
        this.statusType = {
            "0":"已禁用",
            "1":"已开通",
            /*"2":"已启用",*/
            "2":"已激活"
        };
        this.statusCode ={
            "0":"启用",
            "1":"禁用",
            "2":"禁用"
        };
    }
    /*页面初始化*/
    componentWillMount() {
        this.context = this.props.item;
    }

    /*编辑用户*/
    edit(id){
        this.props.edit(id);
    }

    /*修改用户状态*/
    updateStatus(id,status){
        this.props.updateStatus(id,status);
    }

    /*可编辑按钮展示*/
    showMenu(){
        if( 1 != this.context.managerId ){
            return (
                <td style={!Util.authorityCheck("manager") ? {display: 'none'} :{}}>
                    <i className="manager_duty_i" onClick= {this.edit.bind(this,this.context.managerId)}></i>
                    <span style={{"color":"#a0d468",cursor:"pointer"}} onClick={this.updateStatus.bind(this,this.context.managerId,this.context.status)} >
                        {this.statusCode[this.context.status]}
                    </span>
                </td>
            )
        }
    }
    /*渲染页面*/
    render() {
        return (
            <tr>
                <td>{this.context.managerId}</td>
                <td>{this.context.name}</td>
                <td>{this.context.phone}</td>
                <td>{this.context.roleName}</td>
                <td>{this.statusType[this.context.status]}</td>
                {
                    this.showMenu()
                }
            </tr>
        )
    }
}
